<script src="{{ getAssets }}js/ionRangeSlider/js/ion.rangeSlider.js" type="text/javascript"></script>
<script>
$(function(){
	var sph_max = 0,sph_min= -10,sph_step=0.25; //球径
	var cyl_max=0,cyl_min=-2,cyl_step =0.25; //柱径
	$("#range_1").ionRangeSlider({
		min: -30,
		max: 30,
		from:-10,
		to: 0,
		type: 'double',//设置类型
		step: 0.25,
		prefix: "",//设置数值前缀
		postfix: "",//设置数值后缀
		prettify: true,
		hasGrid: true,
		onFinish:function(opt){
			sph_max = opt.toNumber;
			sph_min = opt.fromNumber;
		}
	});
	$("#range_2").ionRangeSlider({
		min: -8,
		max: 8,
		from:-2,
		to: 0,
		type: 'double',//设置类型
		step: 0.25,
		prefix: "",//设置数值前缀
		postfix: "",//设置数值后缀
		prettify: true,
		hasGrid: true,
		onFinish:function(opt){
			cyl_max = opt.toNumber;
			cyl_min = opt.fromNumber;
		}
	});
	$('#submitBtn').click(function(){
		save();
	});
	
	function save() {
		if(sph_max-sph_min<0){
			layer.alert("球镜所选范围不合理");
			return ;
		}else if(cyl_max-cyl_min<0){
			layer.alert("柱镜所选范围不合理");
			return ;
		}
		if((sph_min!=0&&sph_max!=0)&&(sph_min==sph_max)){
			layer.alert("球镜所选范围不合理");
			return ;
		}else if((cyl_min!=0&&cyl_max!=0)&&(cyl_min==cyl_max)){
			layer.alert("柱镜所选范围不合理");
			return ;
		}
		var x  =(sph_max-sph_min)%sph_step;
		var y = (cyl_max-cyl_min)%cyl_step;
		if(x!=0){
			layer.alert("球镜所选区间范围无法计算");
			return ;
		}else if((cyl_max!=0&&cyl_min!=0)&&(sph_max==sph_min)) {
			layer.alert("球镜所选区间范围无法计算");
			return ;
		}
		if(y!=0){
			layer.alert("柱镜所选区间范围无法计算");
			return ;
		}else if((cyl_max!=0&&cyl_min!=0)&&(cyl_max==cyl_min)){
			layer.alert("柱镜所选区间范围无法计算");
			return ;
		}
		if(((sph_max-sph_min)/sph_step)*((cyl_max-cyl_min)/cyl_step)>1000){
			layer.alert("区间选择范围过大，请缩小范围后再添加");
			return ;
		}
		var ranges = {'sph_max':sph_max,'sph_min':sph_min, 'sph_step':sph_step, 'cyl_max':cyl_max, 'cyl_min':cyl_min, 'cyl_step':cyl_step};
        parent.location = updateQueryStringParameter(parent.location.href, 'ranges', JSON.stringify(ranges));
		var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
	}
});
</script>